<div class="container">

    <div class="page-title ui-widget-content ui-corner-all head">
	    <div class="headLeft">
        	<h1 class="icon-48-category-add">Category Manager</h1>
        </div>
    	<div class="headRight">
       		<div id="toolbar" class="toolbar-list">
            	<ul>
                    <li id="toolbar-new" class="button">
                    	<a class="toolbar"  href="<?php echo base_url('cp/category/add') ?>"><span class="icon-32-new"></span>&nbsp;&nbsp;New</a>
                    </li>
                    <li id="toolbar-edit" class="button">
                    	<a class="toolbar" href="#"><span class="icon-32-edit"></span>&nbsp;&nbsp;Edit</a>
                    </li>

                     <li id="toolbar-trash" class="button">
						<a class="toolbar" href="#"><span class="icon-32-trash"></span>&nbsp;&nbsp;Trash</a>
					</li>
					<li id="toolbar-publish" class="button">
	                    <a class="toolbar" href="#"><span class="icon-32-publish"></span>&nbsp;&nbsp;Publish</a>
            	     </li>
                </ul>
            </div>
        </div>
    </div>
    <div class="hastables">
        <div class="detail-post-add clearfix">
        	<form action="<?php echo base_url('cp/category/edit').'/'.$items['id']; ?>" method="post" class="myform" id="myform">


				<table cellpadding="0" cellspacing="0" width="100%" border="0">
                	<tr>
                    	<td height="25" width="120">Name</td>
                        <td><input type="text" name="name" value="<?php echo $items['name'] ?>" class="input" />
                        	<label class="errors"><?php echo form_error('name'); ?></label>
                        </td>
                    </tr>
                    <tr>
                    	<td height="25">Parent</td>
                        <td>
                            <select name="parent" id="parent" class="select">
                            	<option value="0">Please select...</option>
                                <?php
								if($items['level']==0){
									$flag = 0;
								}else {
									$flag = $items['level'];
								}
									foreach($level as $k=>$item){
										if($item['id']==$flag){
											echo '<option value="'.$item['id'].'" selected="selected">'.$item['name'].'</option>';
										}else {
											echo '<option value="'.$item['id'].'">'.$item['name'].'</option>';
										}
									}
								 ?>
                            </select>
                        </td>
                    </tr>
                    <tr>
                    	<td height="25">Sub Level</td>
                        <td>
                            <select name="child" id="child" class="select">
                                <option value="0">Please select...</option>
                                <?php

                                    foreach($sub_level as $val){
                                        if($val['id']==$items['parent']){
                                            echo '<option value="'.$val['id'].'" selected="selected">'.$val['name'].'</option>';
                                        }else {
                                            echo '<option value="'.$val['id'].'">'.$val['name'].'</option>';
                                        }
                                    }
                                ?>
                            </select>
                        </td>
                    </tr>
                     <tr>
                    	<td height="25" width="120">Order No</td>
                        <td><input type="text" name="orderNo" value="<?php echo $items['orderNo']; ?>"  class="input"/></td>
                    </tr>

                    <tr>
                    	<td></td>
                        <td height="30"><input type="submit" name="submit" value="Submit" />
                        	<input type="hidden" name="id" value="<?php echo $items['id'] ?>" />
                        </td>
                    </tr>
                </table>
				</form>
        </div>
    </div>
</div>
<script type="text/javascript">
    jQuery(document).ready(function(){
        jQuery('#parent').change(function(){
            var id = $('#parent option:selected').val();

            jQuery.ajax({
                type: "GET",
                async: false,
                dataType:'json',
                url: base_url + "/category/get_subcats/"+id,
                data: "",
                success: function(data){
                    console.log();
                    jQuery('#child').html(data['option']);

                }
            });
        });
    });
</script>

